/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package uimigration.WidgetsModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import uimigration.Interactions.Behaviour;
import uimigration.Interactions.Widget;
import uimigration.WidgetsModel.Event;
import uimigration.WidgetsModel.Property;
import uimigration.WidgetsModel.WidgetsModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link uimigration.WidgetsModel.impl.EventImpl#getName <em>Name</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.EventImpl#getHandler <em>Handler</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.EventImpl#getEventBehaviourList <em>Event Behaviour</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.EventImpl#getLinkedProperty <em>Linked Property</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.EventImpl#getMappedBehaviorsList <em>Mapped Behaviors</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EventImpl extends EObjectImpl implements Event {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getHandler() <em>Handler</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHandler()
	 * @generated
	 * @ordered
	 */
	protected static final String HANDLER_EDEFAULT = "";

	/**
	 * The cached value of the '{@link #getHandler() <em>Handler</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHandler()
	 * @generated
	 * @ordered
	 */
	protected String handler = HANDLER_EDEFAULT;



	/**
	 * The empty value for the '{@link #getEventBehaviour() <em>Event Behaviour</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEventBehaviour()
	 * @generated
	 * @ordered
	 */
	protected static final Behaviour[] EVENT_BEHAVIOUR_EEMPTY_ARRAY = new Behaviour[0];

	/**
	 * The cached value of the '{@link #getLinkedProperty() <em>Linked Property</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinkedProperty()
	 * @generated
	 * @ordered
	 */
	protected Property linkedProperty;

	/**
	 * The cached value of the '{@link #getMappedBehaviorsList() <em>Mapped Behaviors</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMappedBehaviorsList()
	 * @generated
	 * @ordered
	 */
	protected EList<Behaviour> mappedBehaviors;

	/**
	 * The empty value for the '{@link #getMappedBehaviors() <em>Mapped Behaviors</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMappedBehaviors()
	 * @generated
	 * @ordered
	 */
	protected static final Behaviour[] MAPPED_BEHAVIORS_EEMPTY_ARRAY = new Behaviour[0];



	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return WidgetsModelPackage.Literals.EVENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					WidgetsModelPackage.EVENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getHandler() {
		return handler;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setHandler(String newHandler) {
		String oldHandler = handler;
		handler = newHandler;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					WidgetsModelPackage.EVENT__HANDLER, oldHandler, handler));
	}



	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Behaviour getEventBehaviour(int index) {
		return (Behaviour) getEventBehaviourList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getEventBehaviourLength() {
		return mappedBehaviors == null ? 0 : mappedBehaviors.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEventBehaviour(Behaviour[] newEventBehaviour) {
		((BasicEList<?>) getEventBehaviourList()).setData(
				newEventBehaviour.length, newEventBehaviour);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEventBehaviour(int index, Behaviour element) {
		getEventBehaviourList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Behaviour> getEventBehaviourList() {
		if (mappedBehaviors == null) {
			mappedBehaviors = new EObjectContainmentEList<Behaviour>(Behaviour.class, this,
					WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS);
		}
		return mappedBehaviors;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Property getLinkedProperty() {
		return linkedProperty;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetLinkedProperty(Property newLinkedProperty,
			NotificationChain msgs) {
		Property oldLinkedProperty = linkedProperty;
		linkedProperty = newLinkedProperty;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET,
					WidgetsModelPackage.EVENT__LINKED_PROPERTY,
					oldLinkedProperty, newLinkedProperty);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLinkedProperty(Property newLinkedProperty) {
		if (newLinkedProperty != linkedProperty) {
			NotificationChain msgs = null;
			if (linkedProperty != null)
				msgs = ((InternalEObject) linkedProperty).eInverseRemove(this,
						EOPPOSITE_FEATURE_BASE
								- WidgetsModelPackage.EVENT__LINKED_PROPERTY,
						null, msgs);
			if (newLinkedProperty != null)
				msgs = ((InternalEObject) newLinkedProperty).eInverseAdd(this,
						EOPPOSITE_FEATURE_BASE
								- WidgetsModelPackage.EVENT__LINKED_PROPERTY,
						null, msgs);
			msgs = basicSetLinkedProperty(newLinkedProperty, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					WidgetsModelPackage.EVENT__LINKED_PROPERTY,
					newLinkedProperty, newLinkedProperty));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Behaviour[] getMappedBehaviors() {
		if (mappedBehaviors == null || mappedBehaviors.isEmpty())
			return MAPPED_BEHAVIORS_EEMPTY_ARRAY;
		BasicEList<Behaviour> list = (BasicEList<Behaviour>) mappedBehaviors;
		list.shrink();
		return (Behaviour[]) list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Behaviour getMappedBehaviors(int index) {
		return (Behaviour) getMappedBehaviorsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMappedBehaviorsLength() {
		return mappedBehaviors == null ? 0 : mappedBehaviors.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMappedBehaviors(Behaviour[] newMappedBehaviors) {
		((BasicEList<Behaviour>) getMappedBehaviorsList()).setData(
				newMappedBehaviors.length, newMappedBehaviors);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMappedBehaviors(int index, Behaviour element) {
		getMappedBehaviorsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Behaviour> getMappedBehaviorsList() {
		if (mappedBehaviors == null) {
			mappedBehaviors = new EObjectContainmentEList<Behaviour>(Behaviour.class,
					this, WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS);
		}
		return mappedBehaviors;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Widget getWidgetType() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case WidgetsModelPackage.EVENT__LINKED_PROPERTY:
			return basicSetLinkedProperty(null, msgs);
		case WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS:
			return ((InternalEList<Behaviour>) getMappedBehaviorsList()).basicRemove(
					otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case WidgetsModelPackage.EVENT__NAME:
			return getName();
		case WidgetsModelPackage.EVENT__HANDLER:
			return getHandler();
		case WidgetsModelPackage.EVENT__LINKED_PROPERTY:
			return getLinkedProperty();
		case WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS:
			return getMappedBehaviorsList();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case WidgetsModelPackage.EVENT__NAME:
			setName((String) newValue);
			return;
		case WidgetsModelPackage.EVENT__HANDLER:
			setHandler((String) newValue);
			return;
		case WidgetsModelPackage.EVENT__LINKED_PROPERTY:
			setLinkedProperty((Property) newValue);
			return;
		case WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS:
			getMappedBehaviorsList().clear();
			getMappedBehaviorsList().addAll((Collection<? extends Behaviour>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
		case WidgetsModelPackage.EVENT__NAME:
			setName(NAME_EDEFAULT);
			return;
		case WidgetsModelPackage.EVENT__HANDLER:
			setHandler(HANDLER_EDEFAULT);
			return;
		case WidgetsModelPackage.EVENT__LINKED_PROPERTY:
			setLinkedProperty((Property) null);
			return;
		case WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS:
			getMappedBehaviorsList().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case WidgetsModelPackage.EVENT__NAME:
			return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT
					.equals(name);
		case WidgetsModelPackage.EVENT__HANDLER:
			return HANDLER_EDEFAULT == null ? handler != null
					: !HANDLER_EDEFAULT.equals(handler);
		case WidgetsModelPackage.EVENT__LINKED_PROPERTY:
			return linkedProperty != null;
		case WidgetsModelPackage.EVENT__MAPPED_BEHAVIORS:
			return mappedBehaviors != null && !mappedBehaviors.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", handler: ");
		result.append(handler);
		result.append(')');
		return result.toString();
	}

} //EventImpl
